let Sequelize = require("sequelize");

let sequelize = new Sequelize("qingmei", "root", "root", {
    dialect: "mysql", // 数据库使用mysql
    host: "localhost", // 数据库服务器ip
    port: 3306, // 数据库服务器端口
    pool: {
        max: 10,
        min: 0,
        idle: 10000
    }
});

sequelize
    .authenticate()
    .then(() => {
        console.log('Connection has been established successfully.');
    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });

let answers = sequelize.define(
    "answers",
    {
        trends_id: {
            type: Sequelize.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        answer_content: {
            type: Sequelize.STRING,
            allowNull: false
        },
        answer_from: {
            type: Sequelize.INTEGER,
            allowNull: false
        },
        answer_gender: {
            type: Sequelize.INTEGER,
            allowNull: false
        },
        answer_date: {
            type: Sequelize.STRING,
            allowNull: false
        },
        answer_to: {
            type: Sequelize.INTEGER,
            allowNull: false
        }
    },
    {
        timestamps: false
    }
);
let relations = sequelize.define(
    "users_relations",
    {
        user_id: {
            type: Sequelize.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        follower_id: {
            type: Sequelize.INTEGER,
            allowNull: false
        }
    },
    {
        timestamps: false
    }
);
let mysql = {
    answers: answers,
    relations:relations
};

module.exports = mysql;
